package com.yoi.SendAndRecv;

import com.yoi.bean.Ordermessage;
import com.yoi.service.OrderService;
import org.springframework.amqp.core.Correlation;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;
import java.util.concurrent.TimeUnit;
//Version3
/**
 * 第一个账户发送的Hello1，Hello2的信息
 */
@Component
public class Sender1 {

    @Resource(name="FirstRabbitTemplate")
    private RabbitTemplate firstRabbitTemplate;

    @Autowired
    private OrderService service;


    public void send1() {
        String context = "hello1 " + new Date();
        System.out.println("Sender : " + context);
        this.firstRabbitTemplate.convertAndSend("yoi.exchange1","order.first",context);
       //service.insertOrder(new Ordermessage(15,"First-exchang;hello1.aaa",context));
    }
    public void send2() {
        String context = "hello2 " + new Date();
        System.out.println("Sender : " + context);
        this.firstRabbitTemplate.convertAndSend("yoi.exchange2","order.second", context);
        //service.insertOrderTest2(new Ordermessage(16,"First-exchange;hello2.aaa",context));
    }

    /*public void send1(String dataId,String exchangeName,String routingKey,String message) {

        CorrelationData correlationData=new CorrelationData();
        correlationData.setId(dataId);
        this.firstRabbitTemplate.convertAndSend("yoi.exchange1","my.base1.first",message,correlationData);

        //this.firstRabbitTemplate.convertAndSend("exchange", "", "foo", correlationData);
        //assertTrue(correlationData.getFuture().get(10, TimeUnit.SECONDS).isAck());
    }*/



}